/**
 * Project Name:renshuaipeng-auth
 * File Name:AuthUserInfoController.java
 * Package Name:ren.renshuaipeng.auth.web.controller
 * Date:2015年12月26日 下午10:28:33
 * Copyright (c) 2015, niao.shuai123@163.com All Rights Reserved.
 */

package ren.renshuaipeng.auth.web.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import ren.renshuaipeng.auth.domain.auth.AuthUser;
import ren.renshuaipeng.auth.service.auth.AuthUserService;
import ren.renshuaipeng.auth.web.BaseController;
import ren.renshuaipeng.util.anno.log.OperatorLog;
import ren.renshuaipeng.util.anno.log.OperatorLogType;

/**
 * ClassName: AuthUserInfoController.java<br/>
 * Function: 个人资料编辑. <br/>
 * Date: 2015年12月26日 下午10:28:33<br/>
 *
 * @author 任帅鹏（作者）
 * @version V1.00 （版本号）
 * @see
 * @since JDK 1.8
 */
@Controller
@RequestMapping("/admin/userinfo")
public class AuthUserinfoController extends BaseController {

	private static final String USERINFO_PAGE = "userinfo";

	@Autowired
	private AuthUserService authUserService;

	@RequestMapping
	public String userInfoPage(HttpSession session, Model model) {
		model.addAttribute("userinfo", authUserService.findOne(getAuthUser(session)));
		return USERINFO_PAGE;
	}

	@RequestMapping(method = RequestMethod.POST)
	@OperatorLog(getInfo = "编辑个人资料", getType = OperatorLogType.UPDATE)
	public String userInfo(AuthUser authUser, HttpSession session) {
		AuthUser authUser_ = authUserService.findOne(getAuthUser(session));
		authUser_.setRealName(authUser.getRealName());
		authUser_.setEmail(authUser.getEmail());
		authUser_.setPhoneNo(authUser.getPhoneNo());
		authUserService.save(authUser_, false);
		return "redirect:/admin/userinfo";
	}
}
